#!/usr/bin/env python


import urllib.request
import urllib.parse
import json


class City(object):

    KEY = "5j1znBVAsnSf5xQyNQyq"
    AQI_URL = "http://www.pm25.in/api/querys/pm10.json?city=%s&token=%s&stations=no" % ("%s", KEY)

    def __init__(self, name):
        self._name = name

    @property
    def name(self):
        return self._name

    @property
    def aqi(self):
        resp = urllib.request.urlopen(self.AQI_URL % urllib.parse.quote(self._name))
        result = resp.read()
        return json.loads(result.decode("UTF-8"))[0]['aqi']
